package io.renren.modules.web.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.modules.web.vo.TestPaperSonVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.web.entity.TestpapersonEntity;
import io.renren.modules.web.service.TestpapersonService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 试卷中的试题
 *
 * @author chensixiang
 * @email chensixiang1234@gmail.com
 * @date 2021-08-29 16:56:05
 */
@RestController
@RequestMapping("web/testpaperson")
public class TestpapersonController {
    @Autowired
    private TestpapersonService testpapersonService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("web:testpaperson:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = testpapersonService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("web:testpaperson:info")
    public R info(@PathVariable("id") Long id){
		TestpapersonEntity testpaperson = testpapersonService.getById(id);

        return R.ok().put("testpaperson", testpaperson);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("web:testpaperson:save")
    public R save(@RequestBody TestpapersonEntity testpaperson){
		testpapersonService.save(testpaperson);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("web:testpaperson:update")
    public R update(@RequestBody TestpapersonEntity testpaperson){
		testpapersonService.updateById(testpaperson);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("web:testpaperson:delete")
    public R delete(@RequestBody TestPaperSonVo vo){
        testpapersonService.deleteTestPaperSon(vo.getIds(), vo.getTestPaperId());

        return R.ok();
    }

}
